import request from "../../../utils/request";
import type { Response, Record } from '../part/getRoleListType'
enum API {
  GETROLELIST_URL = '/admin/acl/role/',
  ADDROLE_URL = '/admin/acl/role/save',
  MODIFYROLE_URL = '/admin/acl/role/update',
  DELETEROLE_URL = '/admin/acl/role/remove/',
  GETPOWER_URL = '/admin/acl/permission/toAssign/',
  PERMISSION_URL = '/admin/acl/permission/doAssign'
}
export const reqGetRoleList = (page: number, limit: number, roleName: string) => request.get<any, Response>(API.GETROLELIST_URL + `${page}/${limit}/?roleName=${roleName}`)
export const reqAddOrModify = (data: Record) => {
  if (data.id) {
    request.put<any, any>(API.MODIFYROLE_URL, data)
  } else {
    request.post<any, any>(API.ADDROLE_URL, data)
  }
}
export const reqDeleteRole = (id: number) => request.delete<any, any>(API.DELETEROLE_URL + id)
export const reqGetPower = (roleId: number) => request.get<any, any>(API.GETPOWER_URL + roleId)
export const reqPermission = (roleId: number, permissionId: number[]) => request.post(API.PERMISSION_URL + `?roleId=${roleId}&permissionId=${permissionId}`)